
@echo off

if "%1"=="" (
    echo need a file to process.
) else (
    if not exist "%1.sortip.log" (
        call sortip.cmd "%1" 
    )
    if "%2"=="" (
        set bound=20
    ) else (
        set bound=%2
    )
    del /q "%1.sortipaddress.log" 1> nul 2>nul
    del /q temp.log 1> nul 2> nul
    for /f %%x in ('selectwhere 1 n + "%bound%" "%1.sortip.log" /- ^| select -c 0 /- /-') do (apnic.cmd %%x >> temp.log)
    combinew "%1.sortip.log" * temp.log * "%1.sortipaddress.log"
    del /q temp.log 1> nul 2> nul
)

